package net.lainiao.zhihu.service;

import net.lainiao.zhihu.common.Common;
import net.lainiao.zhihu.common.MyPage;
import net.lainiao.zhihu.dao.ZhihuhuatiMapper;
import net.lainiao.zhihu.model.Zhihuhuati;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2016/1/14.
 */
@Service
public class ZhihuhuatiService {
    @Resource
    private ZhihuhuatiMapper zhihuhuatiMapper;
    private List<Zhihuhuati> list;

    public List<Zhihuhuati> getPage(MyPage page) {
        return zhihuhuatiMapper.getPage(page);    }

    public Zhihuhuati info(String id) {
        return zhihuhuatiMapper.selectByPrimaryKey(id);
    }

    public int dels(String ids) {
        String[] strs = ids.split(",");
        if (strs.length > 0) {
            return zhihuhuatiMapper.dels(strs);
        }
        return 0;
    }

    public int save(Zhihuhuati zhihuhuati) {
        if (StringUtils.isEmpty(zhihuhuati.getId())) {
            zhihuhuati.setId(Common.getNewUUID());
            zhihuhuati.setStatus(0);
            return zhihuhuatiMapper.insert(zhihuhuati);
        }
        return zhihuhuatiMapper.updateByPrimaryKey(zhihuhuati);
    }

    public List<Zhihuhuati> getList() {
        return zhihuhuatiMapper.getList();
    }
}
